#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

import sys
from PyQt4 import QtGui, QtCore


class Main(QtGui.QMainWindow):

    # 自定义槽和函数,注意型号定义必须在class最外层
    # 声明一个无参数的信号
    sin1 = QtCore.pyqtSignal()
    # 声明带一个int类型参数的信号
    sin2 = QtCore.pyqtSignal(int)
    # 声明带一个int和str类型参数的信号
    sin3 = QtCore.pyqtSignal(int, str)
    # 声明带一个列表类型参数的信号
    sin4 = QtCore.pyqtSignal(list)
    # 声明带一个字典类型参数的信号
    sin5 = QtCore.pyqtSignal(dict)
    # 声明一个多重载版本的信号，包括了一个带int和str类型参数的信号，以及带str参数的信号
    sin6 = QtCore.pyqtSignal([int, str], [str])
    # 声明带一个str类型参数的信号
    sin7 = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self)
        self.setWindowTitle('QMainWindow')
        self.setGeometry(300, 300, 300, 300)
        self.mainqw = QtGui.QWidget(self)
        self.mainqw.resize(300, 300)
        grid = QtGui.QGridLayout(self.mainqw)

        # 普通连接方式1
        self.btclose1 = QtGui.QPushButton('btclose1')
        grid.addWidget(self.btclose1)
        self.connect(self.btclose1, QtCore.SIGNAL('clicked()'), QtCore.SLOT('close()'))
        # 普通连接方式2
        self.btclose2 = QtGui.QPushButton('btclose2')
        grid.addWidget(self.btclose2)
        self.connect(self.btclose2, QtCore.SIGNAL('clicked()'), self.closeit)
        # 普通连接方式3
        self.btclose3 = QtGui.QPushButton('btclose3')
        grid.addWidget(self.btclose3)
        self.btclose3.clicked.connect(self.closeit)
        # 普通连接方式4
        self.btclose4 = QtGui.QPushButton('btclose4')
        grid.addWidget(self.btclose4)
        QtCore.QObject.connect(self.btclose4, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('close()'))



        # 信号连接到指定槽
        self.sin1.connect(self.sin1Call)
        self.sin2.connect(self.sin2Call)
        self.sin3.connect(self.sin3Call)
        self.sin4.connect(self.sin4Call)
        self.sin5.connect(self.sin5Call)
        self.sin6[int, str].connect(self.sin6Call)
        self.sin6[str].connect(self.sin6OverLoad)
        self.sin7.connect(self.sin7Call)

        # 信号发射
        self.sin1.emit()
        self.sin2.emit(1)
        self.sin3.emit(1, "text")
        self.sin4.emit([1, 2, 3, 4])
        self.sin5.emit({"name": "codeio", "age": "25"})
        self.sin6[int, str].emit(1, "text")
        self.sin6[str].emit("text")
        self.sin7.emit("text")

    def sin1Call(self):
        print("sin1 emit")

    def sin2Call(self, val):
        print("sin2 emit,value:", val)

    def sin3Call(self, val, text):
        print("sin3 emit,value:", val, text)

    def sin4Call(self, val):
        print("sin4 emit,value:", val)

    def sin5Call(self, val):
        print("sin5 emit,value:", val)

    def sin6Call(self, val, text):
        print("sin6 emit,value:", val, text)

    def sin6OverLoad(self, val):
        print("sin6 overload emit,value:", val)

    def sin7Call(self, val):
        print val

    def closeit(self):
        sys.exit()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = Main()
    main.show()
    sys.exit(app.exec_())